﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Domain.Repository;
using MAF.Common;

namespace Domain
{
    /// <summary>
    /// 便签管理类
    /// </summary>
    public class Memo
    {
        /// <summary>
        /// 新增便签
        /// </summary>
        /// <param name="info"></param>
        public void AddNote(Note info)
        {
            // 如果内容不为空，新增
            if(!string.IsNullOrWhiteSpace(info.Content))
                Storage.MemNotes.Add(info);
        }

        /// <summary>
        /// 更新便签
        /// </summary>
        /// <param name="info"></param>
        public void UpdateNote(Note info)
        {
            if (string.IsNullOrWhiteSpace(info.Content))
            {
                Storage.MemNotes.Remove(info.Id);
                return;
            }

            Storage.MemNotes.Update(info);
        }

        /// <summary>
        /// 把便签转到存档（完成）
        /// </summary>
        /// <param name="id"></param>
        public void CompleteNote(Guid id)
        {
            var note = Storage.MemNotes.GetById(id);
            if (null != note)
            {
                note.IsComplete = true;
                Storage.MemNotes.Update(note);
            }
        }

        /// <summary>
        /// 展示所有便签
        /// </summary>
        /// <returns></returns>
        public List<Note> ShowNotes()
        {
            var q = new Query<Note>();
            q.AddCriterion("IsComplete", Op.Equals, false);
            return Storage.MemNotes.GetByQuery(q);
        }
    }
}
